<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */
    
    /*********************************************************
    *            --== InArch ==--
    *
    * Ajax Drop Page
    *
    * @author Thomas Brandstätter <tb.essentialmind.com>
    * @version n/a
    * @copyright essentialmind.com 2010
    *
    *********************************************************/

    /***
    * class ajaxDropPage
    ****
    * This class will drop a page reference via an AJAX method
    ****
    * @package ajax
    * @author Thomas Brandstätter <tb.essentialmind.com>
    * @version n/a
    * @copyright essentialmind.com 2010
    ***/
    class ajaxNextOrderPosition extends ajaxAction{

        public function process(){
            $scope = 		(int)$_REQUEST['scope'];
            $otype =        $_REQUEST['otype'];
            
            // try to copy the page
            try{
                $nextPos = -1;
                
                // the query differs with the scope, page or folder
                if ($otype == 'page') { 
                    
                    $nextPos = $this->db->getOne("  SELECT count(*) 
                                                    FROM pagemap 
                                                    WHERE nodeid = " . $scope);
                } elseif ($otype == 'folder') { 
                    
					if ($GLOBALS['_CONFIG']['enable_order_position']) { 
                    	$nextPos = $this->db->getOne("  SELECT max(order_pos) 
	                                                    FROM structure 
	                                                    WHERE parent_id = " . $scope);
				    } else {
						$nextPos = 0;
					}
                }
                    
                $nextPos++;
                $this->r->nextPosition = $nextPos;
                
            //something went wrong
            }catch(exception $e){
                //log error
                $this->log->recordError($e->getMessage());
            
                //do nothing
            }
        }
    }
?>